<?php
    $urlfile = fopen("./data/url.appcache","w+");
    fclose($urlfile);
    tree("./themes/daoshi/Public");
    $basedata = file_get_contents("./data/base.appcache");
    $datastr = "CACHE MANIFEST\r\n#".
    date("Y-m-d H:i:s")."\r\n".$basedata."\r\n";
    $datastr .= file_get_contents("./data/url.appcache");
    $link = mysql_connect("localhost","root","zzsmsc66613999");
    if(!$link){
        die("数据库连接失败！");
    }
    mysql_select_db("zzsmsc_ds",$link);
    $data = mysql_query('SELECT * from ds_attachment');
    mysql_close($link);
    while ($row = mysql_fetch_array($data, MYSQL_ASSOC)) {
        $datastr.="/uploads".$row['savepath']."m_".$row['savename']."\r\n";
    }
    $datastr .= "\r\nNETWORK:\r\n\r\n"."FALLBACK:\r\n";
    $myfile = fopen("./data/data.appcache","w+");
    fwrite($myfile,$datastr);
    fclose($myfile);
    echo "AppCache生成成功！";
    function tree($directory)
    {
        $str = "";
        $mydir = dir($directory);
        while($file = $mydir->read())
        {
            if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!=".."))
            {
                //$str .= $file;
                tree("$directory/$file");
            }
            else{
                if(($file!=".") AND ($file!="..")){
                    $str .= substr($directory."/".$file."\r\n","1");
                   
                }
            }
        }
        if($str!=""){
            $urlfile = fopen("./data/url.appcache","a");
            fwrite($urlfile,$str);
            fclose($urlfile);
        }
        $mydir->close();
    }
?>